package com.zhou.review3.controller;

import com.zhou.review3.entity.SysOrder;
import com.zhou.review3.serviceImpl.SysOrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/SysOrder")
public class SysOrderController {
    @Autowired
    private SysOrderServiceImpl sysOrderService;
    //查看内容
    @RequestMapping("list.do")
    public String list(Model model){
        List<SysOrder> sysOrders=sysOrderService.findAllSysOrder();
        model.addAttribute("sysOrders",sysOrders);
        return "listSysOrders";
    }

    //删除
    @RequestMapping("delete.do")
    public String delete(int id,Model model){
        sysOrderService.removeSysOrder(id);
        return list(model);
    }

    //toAdd.do,准备增加
    @RequestMapping("toAdd.do")
    public String toAdd(Model model){
        List<SysOrder> sysOrder=sysOrderService.findAllSysOrder();
        model.addAttribute("sysOrder",sysOrder);
        return "addSysOrder";
    }
    //增加
    @RequestMapping("add.do")
    public String add(SysOrder sysOrder,Model model){
        sysOrderService.addSysOrder(sysOrder);
        return list(model);
    }

    //更新
    @RequestMapping("toUpdate.do")
    public String toUpdate(int id,Model model){
        SysOrder oldsysOrder=sysOrderService.findSysOrder(id);
        model.addAttribute("oldsysOrder",oldsysOrder);
        return "updateSysOrder";
    }
    //update,更新数据到数据库，回到listStudents.html
    @RequestMapping("update.do")
    public String update(SysOrder newsysOrder,Model model){
        sysOrderService.modifySysOrder(newsysOrder);
        return list(model);
    }

}
